package com.yzion.baselib.widget.dialog

import android.content.Context
import android.text.TextUtils
import android.view.View
import com.yzion.baselib.R
import com.yzion.baselib.databinding.ByDialogLoadingBinding
import com.yzion.baselib.dialog.BaseLoadingDialog

/**
 * ZJJ
 * 默认样式的等待加载中的弹窗
 * 实现自定义加载弹窗可继承BaseLoadingDialog，然后在App中的 createLoadingDialog 实现全局初始化，注意：App需继承BaseApp
 */
open class DefaultLoadingDialog(context: Context) : BaseLoadingDialog(context) {

    var binding: ByDialogLoadingBinding? = null

    private var message: String? = null
        set(value) {
            field = value
            binding?.baseTvLoadingTip?.text = field
            if (TextUtils.isEmpty(field)) binding?.baseTvLoadingTip?.visibility =
                View.GONE else binding?.baseTvLoadingTip?.visibility = View.VISIBLE
        }

    override fun initView() {
        binding = ByDialogLoadingBinding.bind(view)
        binding!!.baseTvLoadingTip.text = message
        if (TextUtils.isEmpty(message)) binding!!.baseTvLoadingTip.visibility =
            View.GONE else binding!!.baseTvLoadingTip.visibility = View.VISIBLE
    }

    override fun getLayoutId(): Int {
        return R.layout.by_dialog_loading
    }

    /**
     * 设置加载提示内容
     */
    override fun setLoadingTip(msg: String?): DefaultLoadingDialog {
        message = msg
        return this
    }

    override fun initData() {

    }
}